/* NOTICE
    OpenJaWS - Open Java Weather Station
    
    Copyright (C) 2008 Grant Gardner <grant@lastweekend.com.au>
    
    OpenJaWS is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
NOTICE */
package au.com.lastweekend.openjaws.api;

import au.com.lastweekend.openjaws.units.WindUnit;

/**
 * Adds "direction" to the a unit value of WindSpeed.
 * 
 * Direction is in degrees with methods to turn that into 
 * 32 point compass values.
 * 
 * @author ggardner
 *
 */
public class WindUnitValue extends UnitValue {

    // TODO: Localise
    private static final String[] COMPASS_ROSE = {"N", "NbE", "NNE", "NEbN", "NE", "NEbE", "ENE", "EbN", "E", "EbS", "ESE",
            "SEbE", "SE", "SEbS", "SSE", "SbE", "S", "SbW", "SSW", "SWbS", "SW", "SWbW", "WSW", "WbS", "W", "WbN", "WNW", "NWbW",
            "NW", "NWbN", "NNW", "NbW"};

    public static final WindUnitValue NULL = new WindUnitValue();
    
    private Double direction; // degrees.

    protected WindUnitValue() {
        super();
        
    }

    public WindUnitValue(double currentValue, WindUnit unit) {

        this(currentValue, unit, null);
    }

    public WindUnitValue(double currentValue, WindUnit unit, double direction) {

        this(currentValue, unit, Double.valueOf(direction));
    }

    private WindUnitValue(double currentValue, WindUnit unit, Double direction) {

        super(currentValue, unit);
        this.direction = direction;
    }

    public Double getDirection() {

        return direction;
    }

    public String getCompassDirection() {

        if (direction == null) {
            return "";
        }

        return COMPASS_ROSE[(int) (Math.round(direction / 11.25) % 32)];
    }

    @Override
    public String toString() {
           return format("%f %s %s");
    }

    @Override
    public Object[] formatArgs() {

        return new Object[]{super.formatArgs(), getCompassDirection()};

    }
}
